import myaxios from '../../utils/myaxios'

//获取首页轮播图
const getHomeSwiperImg=()=>{
    return (dispatch)=>{
        myaxios.get('/home/swiperdata').then(res=>{
            dispatch({
                type:'GET_HOME_IMG',
                payload:{
                    swiperList:res,
                    isShow:true
                }
            })
        })
    }
}
//首页导航
const getHomeNavList=()=>{
    return (dispatch)=>{
        myaxios.get('/home/catitems').then(res=>{
            dispatch({
                type:'GET_HOME_NAV',
                payload:{
                    navList:res
                }
            })
        })
    }
}
//获取首页的商品
const getHomeProduct=()=>{
    return (dispatch)=>{
        myaxios.get('/home/floordata').then(res=>{
            dispatch({
                type:'GET_HOME_PRODUCT',
                payload:{
                    productList:res
                }
            })
        })
    }
}
//获取搜索中心的数据
const getSearch=(title,callback)=>{
    return (dispatch)=>{
        myaxios.get('goods/qsearch',{
            params: {
                query:title,
            }
        }).then(res=>{
            callback(res)
            dispatch({
                type:'GET_SEARCH_STATE',
                payload:{
                    searchiList:res
                }
            })
        }).catch(err=>{
            console.log(err)
        })
    }
}

export {getHomeSwiperImg,getHomeNavList,getHomeProduct,getSearch}